package com.future.offer;

import com.future.util.TreeNode;

/**
 * Description: 剑指 Offer 55 - I. 二叉树的深度
 *
 * @author weiruibai.vendor
 * Date: 2023/1/6 09:18
 */
public class Solution_55 {

    int height = 0;
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return height;
        }
        calcMaxHeight(root, 0);
        return height;
    }

    /**
     *    3
     *    / \
     *   9  20
     *     /  \
     *    15   7
     * @param root
     * @param tmpHeight
     */
    private void calcMaxHeight(TreeNode root, int tmpHeight) {
        if (root == null) {
            return;
        }
        tmpHeight++;
        height = Math.max(tmpHeight, height);
        calcMaxHeight(root.left, tmpHeight);
        calcMaxHeight(root.right, tmpHeight);
    }
}
